<%@page import="aa.db.DBTools"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>数据查询</h1>
<hr>
<%
//接收数据kw
request.setCharacterEncoding("utf-8");
String key = request.getParameter("kw");
if(key==null){
	key="";
}
%>
<form method="post">
请输入查询条件: <input type="text"name="kw" value="<%=key%>"/>
<input type="submit" value="查询"/>
</form>
<%
//处理表单提交的数据


if(key.length()>0){
    

//构造sQL
String sql = "SELECT * FROM hotel WHERE city like '%"+key+"%' or name LIKE'%"+key+"%'";
//out.println(sql);
//out.println("<br>");

//查询DB---->rs
/*Class.forName("org.mariadb.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mariadb://10.220.140.102:3366/studb11","stua","zHZUA65r");
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(sql);
*/
//sql--->rs

javax.sql.rowset.WebRowSet rs = aa.db.DBTools.getRS(sql);



//显示rs结果
out.println("<table width='80%' border='1'>");
out.println("<tr><th>酒店名</th><th>城市</th><th>评分</th><th>房型</th></tr>");
while (rs.next()){
	out.println("<tr>");
	out.println("<td>"+rs.getString("name")+"</td>");
	out.println("<td>"+rs.getString("city")+"</td>");
	out.println("<td>"+rs.getString("score")+"</td>");
	out.println("<td>"+rs.getString("type")+"</td>");
	out.println("</tr>");
}
out.println("</table>");
rs.close();


}
%>

</body>
</html>